

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The thread module &mdash; pyamp v1.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="pyamp v1.2 documentation" href="../index.html" />
    <link rel="up" title="The threading module" href="mod_pyamp_processes_threading.html" />
    <link rel="next" title="The coroutine module" href="pyamp_processes_coroutine.html" />
    <link rel="prev" title="The threading module" href="mod_pyamp_processes_threading.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_processes_coroutine.html" title="The coroutine module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod_pyamp_processes_threading.html" title="The threading module"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_processes.html" >The processes module</a> &raquo;</li>
          <li><a href="mod_pyamp_processes_threading.html" accesskey="U">The threading module</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-pyamp.processes.threading.thread">
<span id="the-thread-module"></span><h1>The thread module<a class="headerlink" href="#module-pyamp.processes.threading.thread" title="Permalink to this headline">¶</a></h1>
<p>The thread module contains the Thread class which provides the ability to
create a threaded class. The Thread class manages starting the thread, and
shutting it down appropriately. The subclasses Thread will can be notified when
the thread starts, is shut down, or at each cycle so it can perform some
process.</p>
<div class="section" id="the-thread-class">
<h2>The Thread class<a class="headerlink" href="#the-thread-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-2eb4730e351f3a4658ed19c02291d9f00c103954.png" alt="Inheritance diagram of pyamp.processes.threading.thread.Thread" usemap="#inheritance1ac7bcd29a" class="inheritance"/>
<map id="inheritance1ac7bcd29a" name="inheritance1ac7bcd29a">
<area shape="rect" href="#pyamp.processes.threading.thread.Thread" title="pyamp.processes.threading.thread.Thread" alt="" coords="33,161,327,188"/>
<area shape="rect" href="pyamp_logging_loggable.html#pyamp.logging.loggable.Loggable" title="pyamp.logging.loggable.Loggable" alt="" coords="167,84,401,111"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.processes.threading.thread.Thread">
<em class="property">class </em><tt class="descclassname">pyamp.processes.threading.thread.</tt><tt class="descname">Thread</tt><big>(</big><em>conditionFn=&lt;function &lt;lambda&gt; at 0x912e224&gt;</em>, <em>logger=None</em><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread" title="Permalink to this definition">¶</a></dt>
<dd><p>The Thread class provides a base class for creating threaded classes. It
is essentially a wrapper for the <a class="reference external" href="http://docs.python.org/library/threading.html#threading.Thread" title="(in Python v2.7)"><tt class="docutils literal"><span class="pre">threading.Thread</span></tt></a> class to make
threaded classes easier to manage.</p>
<p>It provides the following functions that can be overridden by subclasses:</p>
<ul>
<li><p class="first">onStart(self) &#8211; This function is called when the Thread is started.</p>
</li>
<li><dl class="first docutils">
<dt>onException(self, e, trace) &#8211; This function is called in the event that</dt>
<dd><p class="first last">an exception is encountered while the
Thread is cycling.</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>onCycle(self, increment) &#8211; This function is called once each time the</dt>
<dd><p class="first last">Thread cycles.</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>onShutdown(self) &#8211; This function is called in the event that the Thread</dt>
<dd><p class="first last">is shutdown.</p>
</dd>
</dl>
</li>
</ul>
<p>Once the Thread has started it continues to run until the <a class="reference internal" href="#pyamp.processes.threading.thread.Thread.shutdown" title="pyamp.processes.threading.thread.Thread.shutdown"><tt class="xref py py-func docutils literal"><span class="pre">shutdown()</span></tt></a>
function is called, or until the condition function returns False.</p>
<p>Subclasses can set the Period property which sets the number of seconds
that the Thread will sleep at the end of each cycle. The default value is
one millisecond.</p>
<p>This class implements the <a class="reference internal" href="../logging.html#pyamp.logging.Loggable" title="pyamp.logging.Loggable"><tt class="xref py py-class docutils literal"><span class="pre">pyamp.logging.Loggable</span></tt></a> interface.</p>
<ul class="simple">
<li>conditionFn &#8211; A function that determines when the Thread should exit</li>
<li>logger &#8211; The logger for this class</li>
</ul>
<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.isRunning">
<tt class="descname">isRunning</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.isRunning"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.isRunning" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if the Thread is still running.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.onCycle">
<tt class="descname">onCycle</tt><big>(</big><em>increment</em><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.onCycle"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.onCycle" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is called when at each cycle of the Thread and should
be overridden by subclasses.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function should be overridden by concrete Threads.</p>
</div>
<ul class="simple">
<li>increment &#8211; The current increment number</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.onException">
<tt class="descname">onException</tt><big>(</big><em>e</em>, <em>trace</em><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.onException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.onException" title="Permalink to this definition">¶</a></dt>
<dd><p>The Thread encountered an exception.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function should be overridden by concrete Threads.</p>
</div>
<ul class="simple">
<li>e &#8211; The exception</li>
<li>trace &#8211; The traceback for the exception</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.onShutdown">
<tt class="descname">onShutdown</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.onShutdown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.onShutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is called when the Thread is shut down and should
be overridden by subclasses.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function should be overridden by concrete Threads.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.onStart">
<tt class="descname">onStart</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.onStart"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.onStart" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is called when the Thread is started and should
be overridden by subclasses.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function should be overridden by concrete Threads.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.onStop">
<tt class="descname">onStop</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.onStop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.onStop" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is called when the Thread is stopped.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function should be overridden by concrete Threads.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.run">
<tt class="descname">run</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.run"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the Thread until it is shut down or its condition function
returns False.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Thread.shutdown">
<tt class="descname">shutdown</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Thread.shutdown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Thread.shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Shutdown the Thread.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-cycle-class">
<h2>The Cycle class<a class="headerlink" href="#the-cycle-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-762715df111d869d99ee30c6708ed12d35a18be0.png" alt="Inheritance diagram of pyamp.processes.threading.thread.Cycle" usemap="#inheritance04168648bb" class="inheritance"/>
<map id="inheritance04168648bb" name="inheritance04168648bb">
<area shape="rect" href="pyamp_logging_loggable.html#pyamp.logging.loggable.Loggable" title="pyamp.logging.loggable.Loggable" alt="" coords="29,7,264,33"/>
<area shape="rect" href="#pyamp.processes.threading.thread.Cycle" title="pyamp.processes.threading.thread.Cycle" alt="" coords="5,84,288,111"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.processes.threading.thread.Cycle">
<em class="property">class </em><tt class="descclassname">pyamp.processes.threading.thread.</tt><tt class="descname">Cycle</tt><big>(</big><em>conditionFn</em>, <em>logger=None</em><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Cycle"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Cycle" title="Permalink to this definition">¶</a></dt>
<dd><p>The Cycle class provides a class which will continue cycling until
a condition is no longer True.</p>
<ul class="simple">
<li>conditionFn &#8211; The condition function</li>
<li>logger &#8211; The logger object</li>
</ul>
<dl class="method">
<dt id="pyamp.processes.threading.thread.Cycle.shutdown">
<tt class="descname">shutdown</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Cycle.shutdown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Cycle.shutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Stop cycling.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.processes.threading.thread.Cycle.start">
<tt class="descname">start</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/processes/threading/thread.html#Cycle.start"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.processes.threading.thread.Cycle.start" title="Permalink to this definition">¶</a></dt>
<dd><p>Start cycling until the condition function returns False.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The thread module</a><ul>
<li><a class="reference internal" href="#the-thread-class">The Thread class</a></li>
<li><a class="reference internal" href="#the-cycle-class">The Cycle class</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="mod_pyamp_processes_threading.html"
                        title="previous chapter">The threading module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pyamp_processes_coroutine.html"
                        title="next chapter">The coroutine module</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/_generated/pyamp_processes_threading_thread.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_processes_coroutine.html" title="The coroutine module"
             >next</a> |</li>
        <li class="right" >
          <a href="mod_pyamp_processes_threading.html" title="The threading module"
             >previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_processes.html" >The processes module</a> &raquo;</li>
          <li><a href="mod_pyamp_processes_threading.html" >The threading module</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Brett Ponsler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
    </div>
  </body>
</html>